<!DOCTYPE html>
<html>
<head>
    <title>模块管理</title>
    <link rel="stylesheet" href="__STATIC__/js/layui-v2.5.5/css/layui.css">
	<style>
		.layui-legend-size{font-size:14px !important;}
		.layui-nopadding{padding:0 !important;}
		.layui-overflow{overflow:auto;}
		.layui-nomargin{margin: 0 !important;}
		.layui-bottom{border-bottom:1px solid rgb(226, 226, 226);}
		.layui-input{height:30px !important; }
		.layui-form-search-item .layui-inline{margin-bottom: 5px;} 
		.layui-form-search-item label{margin-left: 15px;}
		.layui-table-page {padding: 7px 0px 0px;}
		.layui-field-padding{border-width: 1px;padding:0 0 5px 10px;}
		
		.switch-left,.switch-right{
            	width: 30px;height: 25px;display: inline-block;cursor: pointer;font-size: 12px;line-height: 25px;text-align: center;color: white;font-weight: 800;
            	background-color: #ccc;
            }
            .switch-left{
            	/*background-color:#08BC70 ;*/
            	border-radius: 3px 0px 0px 3px;
            	border-right: 1px solid block;
            }
            .switch-right{
            	/*background-color: #ccc;*/
            	border-radius: 0px 3px 3px 0px;
            	border-left: 1px solid block;
            }
            .switch-off{
            	background-color: red;
            }
            .switch-on{
            	background-color: #08BC70 ;
            }
	</style>
</head>
<body>
	<!-- layui-tab开始 -->
	<div class="layui-tab " lay-filter="demo-tab">
		<!-- 顶部导航菜单开始 -->
		<div class="layui-tab-nav" >
	        <ul class="layui-tab-title">
				<?php $currentTab=2; ?>
				<include file="public/../module_manage/nav" />
			</ul>
		</div>
		<!-- 顶部导航菜单结束 -->

		<!-- 搜索栏开始 -->
		<fieldset class="layui-elem-field layui-field-title layui-field-padding">
			<legend class="layui-legend-size">搜索</legend>
			<form class="layui-form table-bar" action="{:url('ModulePlugin/index')}" lay-filter="form-bar" method="post">
				<div class="layui-form-search-item">
				
					<div class="layui-inline">
						<label>模块选择</label>
						<div class="layui-input-inline">
							<select name="mid" lay-verify="required" lay-search="">
						  		<option value="0">全部模块</option>
								<volist name="all" id="vo">
									<option value="{$vo->id}"  <?php if( $vo->id == $search[ 'mid' ]) echo 'selected'; ?>  >{$vo->name}----{$vo->title}</option>
								</volist>
							</select>
						</div>
				    </div>

					
					<div class="layui-inline">
						<button type="submit" class="layui-btn layui-btn-sm layui-btn-primary " style="font-weight:800;" lay-submit="" lay-filter="demo2"><i class="layui-icon ">&#xe615;</i>搜索</button>
					</div>
				</div>
			</form>
		</fieldset>
		<!-- 搜索栏结束 -->
		<div class="layui-card">
			<div class="layui-card-header layui-bg-gray layui-bottom">
				<a href="javascript:;" class="layui-btn layui-btn-xs add-btn" ><i class="layui-icon">&#xe654;</i>添加插件</a>
			</div>
			<div class="layui-card-body layui-nopadding " >
				<table  class="layui-table layui-nomargin" id='tb_list' >
					<thead>
						<tr>
							<th width="50" >ID</th>
							<th  width="50"  >MID</th>
							<th>插件名</th>
							<th>插件标识</th>
							<th>版本</th>
							<th>描述</th>
							<th>上架</th>
							<th>状态</th>
							<th>操作</th>
						</tr>
					</thead>
					<!-- 表格内容输出 -->
					<tbody>
					<volist name="list" id="vo">
						<tr>
							<td>{$vo->id}</td>
							<td>{$vo->mid}</td>
							<td>{$vo->name}</td>
							<td>{$vo->title}</td>
							<td>{$vo->version}</td>
							<td>{$vo->describe}</td>
							<td>
								<div class="putway_span" data-tag="上架|下架" data-val="{$vo->putway}" data-id="{$vo->id}"></div>
								
							</td>
							<td><?php if($vo->status==0){ echo '开发中';}else if( $vo->status==4){ echo '完成'; }?></td>
							<td width="100" style="text-align:center;">
								<div class="layui-btn-group">
									
									<button type="button" class="layui-btn layui-btn-primary layui-btn-xs upload-btn" data-tag="{$vo->id}" title="源码">
										<i class="layui-icon">&#xe681;</i>
									</button>
									
									<button type="button" class="layui-btn layui-btn-primary layui-btn-xs edit-btn" data-tag="{$vo->id}" title="修改">
										<i class="layui-icon">&#xe642;</i>
									</button>
									<if condition="cmf_get_current_admin_id()==1">
									<button type="button" class="layui-btn layui-btn-primary layui-btn-xs delete-btn" data-tag="{$vo->id}" title="删除">
										<i class="layui-icon">&#xe640;</i>
									</button>
									</if>
								</div>
							</td>
						</tr>
					</volist>
					</tbody>
				</table>
			</div>
		</div>
	</div>
	<!-- layui-tab结束-->
<script src="__STATIC__/js/jquery.js"></script>
<script src="__STATIC__/js/layui-v2.5.5/layui.all.js"></script>
<script type="text/javascript">
	;!function(){
		var form = layui.form
			,layer = layui.layer    //弹出层必需
			,layedit = layui.layedit  //富文本必需
			,laydate = layui.laydate  //日期选择必需
			,table = layui.table  //表格必需
			,element = layui.element;  //选项卡	
			
			
			$( '.add-btn' ).on( 'click' , function(){
				layer.open({
					type: 2,
					title: '添加插件',
					shadeClose: true,
					btn:[ '保存','取消'],
					shade: false,
					maxmin: true, //开启最大化最小化按钮
					area: ['893px', '600px'],
					content: '{:url("ModulePlugin/addPage")}',
					yes:function( index ){
						//调用子页面方法
						parentInfo = window["layui-layer-iframe" + index].callback(index);
					}
				});
				
			} );
			
			$('.delete-btn').click(function(){
				let id = $( this ).data('tag');
				layer.confirm( '确定要删除此模块吗？' , { title: "删除提示" , icon:3 } ,function(){
					$.get( '{:url("ModulePlugin/del")}?id='+ id, function( res ){
						layer.msg( res.message , {icon:(res.code==200 )?1:5 , time:800 } , function(){
							if( res.code == 200 ){
								window.location.reload();
							}
						} );
					 	
					}  );
				} );
			});
			
			
			$( '.edit-btn' ).on( 'click' , function(){
				let id = $(this).data('tag');
				layer.open({
					type: 2,
					title: '修改插件',
					shadeClose: true,
					btn:[ '保存','取消'],
					shade: false,
					maxmin: true, //开启最大化最小化按钮
					area: ['893px', '600px'],
					content: '{:url("ModulePlugin/editPage")}?id='+id,
					yes:function( index ){
						//调用子页面方法
						parentInfo = window["layui-layer-iframe" + index].callback(index);
					}
				});
				
			} );
			
			$( '.upload-btn' ).on( 'click' , function(){
				let id = $(this).data('tag');
				layer.open({
					type: 2,
					title: '源码',
					shadeClose: true,
					btn:[ '关闭'],
					shade: false,
					maxmin: true, //开启最大化最小化按钮
					area: ['893px', '600px'],
					content: '{:url("ModuleManage/resourcePage")}?id='+id+'&type=2'
				});
				
			} );

			
			
			$( '.putway_span' ).each(function(){
				var tx = $(this).data('tag').split('|');
				let value = $(this).data('val');
				let id = $(this).data('id');
				
				var putway = function( ele , x ){
					$.post( '{:url("ModulePlugin/updates")}' , {id:id,putway:x},function( res ){
						layer.msg( res.message , { icon:(res.code==200 )?1:5 , time:1000} , function(){
						
								window.location.reload();
						} );
					} );
				};
				if( tx.length != 2 )return false;
				var eleT = '<div style="width:60px;height:25px;font-size:12px;background-color:#ccc;border-radius:5px;color:white;">';
					eleT+= '<span class="left-span" style="display:inline-block;height:25px;width:30px;line-height:25px;cursor:pointer;text-align:center;border-radius:5px 0px 0px 5px;">'+tx[0]+'</span>';
					eleT+= '<span class="right-span" style="display:inline-block;height:25px;width:30px;line-height:25px;cursor:pointer;text-align:center;border-radius:0px 5px 5px 0px;">'+tx[1]+'</span>';
					eleT+= '</div>';
				$(this).html( eleT );
				let left = $(this).find('.left-span');
				let right = $(this).find('.right-span');
				left.on( 'click' , function(){
					if( value ==1 ) return false;
					left.css( 'background-color' , '#18BC9C' );
					right.css( 'background-color' , '' );
					putway( this , 1 );
				} );
				right.on( 'click' , function(){
					if(value ==0 ) return false;
					left.css( 'background-color' , '' );
					right.css( 'background-color' , 'red' );
					putway( this , 0 );
				} );
				if(value == 1 ){
					left.css( 'background-color' , '#18BC9C' );
					right.css( 'background-color' , '' );
				}else{
					left.css( 'background-color' , '' );
					right.css( 'background-color' , 'red' );
				}
				
			});
			
			
			
			
	}();
</script>

<script>
	

</script>


</body>
</html>